/**
 * Created by huotaol on 2017/4/21.
 */
import * as types from "../../constant/ActionType";

const initLoad = {
    loadModal: {
        loading: false,
        text: '努力加载中...',
    },
};

function loading(state = Object.assign({}, initLoad), action) {
    switch (action.type) {
        case types.LOADING_MODAL:
            return Object.assign({}, state, {
                loadModal: {loading: action.loading, text: action.text,}
            });
        default:
            return state;
    }
}

export const initArea = {
    area: {
        code: 'guiyang',
        id: 1,
        name: '贵阳',
    },
};

function selectArea(state = Object.assign({}, initArea), action) {
    switch (action.type) {
        case types.SELECTED_AREA:
            return Object.assign({}, state, {
                area: {
                    id: action.id,
                    code: action.code,
                    name: action.name,
                },
            });
        default:
            return state;
    }
}

const initHotCarList = {
    data: [],
};

function hotCarList(state = Object.assign({}, initHotCarList), action) {
    switch (action.type) {
        case types.HOT_CAR_LIST:
            return Object.assign({}, state, {
                data: action.data,
            });
        default:
            return state;
    }
}

const initAreaList = {
    data: [],
};
function areaList(state = Object.assign({}, initAreaList), action) {
    switch (action.type) {
        case types.AREA_RECEIVE:
            return Object.assign({}, state, {
                data: action.data,
            });
        default:
            return state;
    }
}

export default {loading, selectArea, areaList, hotCarList};